import { URL, CONF } from "../configure/Assets.js"
import { $$, _toast, app } from "../experience/utils/F7.js";

import Db from "../experience/db/Db.js";
import Api from "../experience/api/Api.js";
import Utils from "../experience/utils/Utils.js";
import Algorithm from "../experience/utils/Algorithm.js";
import Drawer from "../experience/drawer/Drawer.js";
import Net from "../experience/api/Net.js";
import Emitter from "../experience/utils/Emitter.js";

import { ServiceType, LayerType } from "../experience/db/Type.js"

export default class Valkyrja {
    constructor() {
        this.$$ = $$;
        this.app = app;
        this.toast = _toast;
        this.URL = URL;
        this.CONF = CONF;

        this.db = new Db();
        this.net = new Net();
        this.api = new Api();
        this.utils = new Utils();
        this.algo = new Algorithm();
        this.drawer = new Drawer();
        this.emitter = new Emitter();
    }
    async code(){
        const code = await this.api.getCode();
        this.utils.setLocalStorage('code', code.data);
    }

    async update(meta_id) {
        app.dialog.preloader("正在获取矿图...");
        const data = await this.api.getVector(meta_id);
        if (data.code === 0) {
            this.drawer.init(data.data.meta, data.data.layers);
            this.db.init(data.data).then(() => {
                this.drawer.location().then(() => {
                    app.dialog.close();
                });
            });
        } else {
            _toast("未找到图纸,请先上传图纸。");
            app.dialog.close();
        }
    }
}